package cn.tedu.weibo1.controller;

import cn.tedu.weibo1.mapper.UserMapper;
import cn.tedu.weibo1.pojo.dto.UserRegDto;
import cn.tedu.weibo1.pojo.entity.User;
import cn.tedu.weibo1.pojo.vo.UserVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserMapper mapper;

    @RequestMapping("/reg")
    public int regUser(@RequestBody UserRegDto userRegDto) {
        UserVO u = mapper.selectByUsername(userRegDto.getUsername());
        if (u != null) {
            return 2;
        } else {
            User user = new User();
            BeanUtils.copyProperties(userRegDto, user);
            mapper.insertUser(user);
            return 1;
        }
    }
}
